package cn.xxi.ai.workflow.core.node;


import cn.xxi.ai.workflow.state.State;
import lombok.extern.slf4j.Slf4j;
import org.bsc.langgraph4j.action.EdgeAction;

@Slf4j
public abstract class ConditionNode<T extends NodeData> extends Node<T> implements EdgeAction<State> {

    @Override
    public final String apply(State state) {
        log.info("ConditionNode[{}] started, state[{}]", this.getClass().getSimpleName(), state);

        try {
            String result = process(state);
            log.info("ConditionNode[{}] chose branch: {}", this.getClass().getSimpleName(), result);
            return result;
        } catch (Exception e) {
            log.error("ConditionNode[{}] failed: {}", this.getClass().getSimpleName(), e.getMessage(), e);
            throw e;
        }
    }

    protected abstract String process(State state);
}